#ifndef LORA_SERVICE_H
#define LORA_SERVICE_H
#include "data_type.h"
#include "protocol.h"
#include "ring_buffer.h"
#include <string.h>
#include <stdint.h>
#include <sys/time.h> 
#include <time.h> 

typedef struct {
    uint32_t days;
    uint8_t hours;
    uint8_t minutes;
    uint8_t seconds;
    uint16_t milliseconds;
} RuntimeCounter;

typedef struct {
    uint16_t addr;
    uint16_t group_addr;
    uint16_t trans_addr;
    int status;
    short onTime;
    short offTime;
    float batteryVoltage;              //电池电压
    float batteryElectric;              //电池电流
    short batteryCapacity;   //电池容量
    int batteryStatus;                //电池状态

    float loadVoltage;                 //负载电压
    float loadElectric;                 //负载电流
    float loadPower;               //负载功率
    int loadStatus;              //负载状态

    float columnVoltage;                //正列电压
    int columnStatus;              //正列状态

    int runDay;                     //运行天数
    int lowVolCnt;                  //欠压次数
    
    int todayDischarge;             //今日放电数量
    int yesterdayDischarge;         //昨日总放电数量
    int totalDischarge;             //总放电数量
    
    int todayCharge;        //今日充电数量
    int yesterdayCharge;    //昨日充电数量
    int totalCharge;        //总充电数量

    float fDevTemperature;          //设备温度
    float fBatTemperature;          //电池温度
    time_t seconds;
}HeartData;

// 更新运行时长（需在1ms定时器中断中调用）
RuntimeCounter *RuntimeCounter_Update(uint32_t run_sec);
void lora_worker_start(void);

void lora_send(uint8_t *data, int size);

void lora_printf(const char *format, ...);
#endif